package com.pig4cloud.pig.village.contract.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.village.api.dto.LandContractDTO;
import com.pig4cloud.pig.village.api.dto.LandContractTotalDTO;
import com.pig4cloud.pig.village.api.entity.Fund;
import com.pig4cloud.pig.village.api.entity.LandContract;
import com.pig4cloud.pig.village.contract.service.ILandContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author limbray.li
 * @date 2021/6/19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/land-contract")
@Api(value = "land-contract", tags = "土地承包管理")
public class LandContractController {
	@Resource
	private ILandContractService landContractService;

	@GetMapping("/page")
	public R<IPage<LandContractDTO>> page(Integer pageNum, Integer pageSize, Long teamId, Integer year, Long villagerId) {
		return R.ok(landContractService.selectForPage(new Page(pageNum, pageSize),teamId,year,villagerId));
	}

	@PostMapping("/update")
	public R update(@RequestBody LandContract landContract) {
		return R.ok(landContractService.updateById(landContract));
	}

	@GetMapping("/get")
	public R<LandContractDTO> get(Long id) {
		return R.ok(landContractService.getDtoById(id));
	}

	@PutMapping("/deleteById")
	public R delete(Long id) {
		return R.ok(landContractService.removeById(id));
	}

	@PostMapping("/add")
	public R add(@RequestBody LandContract landContract) {
		return R.ok(landContractService.save(landContract));
	}

	@GetMapping("/getTeamTotal")
	@ApiOperation("获取队内的总和")
	public R<List<LandContractTotalDTO>> getTeamTotal(Long teamId, Integer year) {
		return R.ok(landContractService.teamTotal(teamId,year));
	}

	@GetMapping("/getVillageTotal")
	@ApiOperation("获取全村的总和")
	public R<LandContractTotalDTO> getVillageTotal(Integer year) {
		return R.ok(landContractService.villageTotal(year));
	}
}
